
//
//  PayViewController.m
//  联付商圈
//
//  Created by apple on 17/7/19.
//  Copyright © 2017年 lianfu. All rights reserved.
//

#import "PayViewController.h"
#import "ReceiptTableViewCell.h"

@interface PayViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *payWayTableView;
@property (nonatomic, strong) NSArray *imageArr;
@property (nonatomic, strong) NSArray *wordArr;
@end

@implementation PayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self buildMainInterface];
    [self addPayView];
}

- (void)buildMainInterface
{
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    self.navigationItem.title = @"降低费率";
    self.view.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];
    self.imageArr = @[@"银联@2x", @"支付宝@2x", @"微信@2x"];
    self.wordArr = @[@"银联小额", @"支付宝扫码", @"微信小额", @"升级后: 0.38%", @"升级后: 0.38%", @"升级后: 0.38%"];

    self.payWayTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0 * FONTSIZE, SCREENW, 354 * FONTSIZE) style:UITableViewStylePlain];
    self.payWayTableView.scrollEnabled = NO;
    self.payWayTableView.backgroundColor = [UIColor whiteColor];
    self.payWayTableView.delegate = self;
    self.payWayTableView.dataSource = self;
    self.payWayTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_payWayTableView];
    [self.payWayTableView registerClass:[ReceiptTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENW, 50 * FONTSIZE)];
    headerView.backgroundColor = [UIColor whiteColor];
    self.payWayTableView.tableHeaderView = headerView;
    
    UIView *colorView = [[UIView alloc] init];
    colorView.backgroundColor = [UIColor colorWithRed:0.23 green:0.62 blue:0.87 alpha:1.00];
    [headerView addSubview:colorView];
    [colorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headerView.mas_top).offset(10 * FONTSIZE);
        make.bottom.equalTo(headerView.mas_bottom).offset(-10 * FONTSIZE);
        make.left.equalTo(headerView.mas_left).offset(20 * FONTSIZE);
        make.width.mas_equalTo(7 * FONTSIZE);
    }];
    
    UILabel *topLabel = [[UILabel alloc] init];
    topLabel.font = [UIFont systemFontOfSize:20 * FONTSIZE];
    topLabel.text = @"通过费率升级列表如下";
    [headerView addSubview:topLabel];
    [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(UIEdgeInsetsMake(0, 32 * FONTSIZE, 0, 0));
    }];
}

- (void)addPayView
{
    UIView *bottomView = [[UIView alloc] init];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(0);
        make.right.equalTo(self.view.mas_right).offset(0);
        make.bottom.equalTo(self.view.mas_bottom).offset(0);
        make.top.equalTo(_payWayTableView.mas_bottom).offset(10 * FONTSIZE);
    }];
    
    UIView *colorView = [[UIView alloc] initWithFrame:CGRectMake(20 * FONTSIZE, 10 * FONTSIZE, 7 * FONTSIZE, 30 * FONTSIZE)];
    colorView.backgroundColor = [UIColor colorWithRed:0.23 green:0.62 blue:0.87 alpha:1.00];
    [bottomView addSubview:colorView];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(20 * FONTSIZE, 49 * FONTSIZE, SCREENW - 20 * FONTSIZE, 0.8)];
    lineView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1.0];
    [bottomView addSubview:lineView];
    
    UILabel *topLabel = [[UILabel alloc] initWithFrame:CGRectMake(32 * FONTSIZE, 0, SCREENW - 32 * FONTSIZE, 50 * FONTSIZE)];
    topLabel.font = [UIFont systemFontOfSize:20 * FONTSIZE];
    topLabel.text = @"通过费率升级";
    [bottomView addSubview:topLabel];

    
    UIButton *payButton = [UIButton buttonWithType:UIButtonTypeCustom];
    payButton.backgroundColor = [UIColor colorWithRed:0.00 green:0.61 blue:0.89 alpha:1.00];
    [payButton setTitle:@"立即付款" forState:UIControlStateNormal];
    [payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    payButton.layer.cornerRadius = 10;
    [bottomView addSubview:payButton];
    [payButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView.mas_left).offset(20 * FONTSIZE);
        make.right.equalTo(bottomView.mas_right).offset(-20 * FONTSIZE);
        make.bottom.equalTo(bottomView.mas_bottom).offset(-20 * FONTSIZE);
        make.height.mas_equalTo(50 * FONTSIZE);
    }];
    
    UILabel *beforeUpdateLabel = [[UILabel alloc] init];
    beforeUpdateLabel.textColor = [UIColor colorWithWhite:0.8 alpha:1.0];
    beforeUpdateLabel.text = @"原价";
    beforeUpdateLabel.font = [UIFont systemFontOfSize:18 * FONTSIZE];
    [bottomView addSubview:beforeUpdateLabel];
    [beforeUpdateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView.mas_left).offset(20 * FONTSIZE);
        make.top.equalTo(lineView.mas_bottom).offset(20 * FONTSIZE);
        make.width.mas_equalTo(50 * FONTSIZE);
        make.height.mas_equalTo(20 * FONTSIZE);
    }];
    
    UILabel *afterUpdateLabel = [[UILabel alloc] init];
    afterUpdateLabel.text = @"现价";
    afterUpdateLabel.font = beforeUpdateLabel.font;
    [bottomView addSubview:afterUpdateLabel];
    [afterUpdateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomView.mas_left).offset(20 * FONTSIZE);
        make.top.equalTo(beforeUpdateLabel.mas_bottom).offset(20 * FONTSIZE);
        make.width.mas_equalTo(50 * FONTSIZE);
        make.height.mas_equalTo(20 * FONTSIZE);
    }];
    
    UILabel *beforePriceLabel = [[UILabel alloc] init];
    beforePriceLabel.text = [NSString stringWithFormat:@"￥299.00"];
    beforePriceLabel.font = beforeUpdateLabel.font;
    beforePriceLabel.textColor = beforeUpdateLabel.textColor;
    beforePriceLabel.textAlignment = 2;
    [bottomView addSubview:beforePriceLabel];
    [beforePriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bottomView.mas_right).offset(-20 * FONTSIZE);
        make.top.equalTo(lineView.mas_bottom).offset(20 * FONTSIZE);
        make.width.mas_equalTo(100 * FONTSIZE);
        make.height.mas_equalTo(20 * FONTSIZE);
    }];
    
    UILabel *afterPriceLabel = [[UILabel alloc] init];
    afterPriceLabel.text = [NSString stringWithFormat:@"￥99.00"];
    afterPriceLabel.font = [UIFont systemFontOfSize: 25 * FONTSIZE];
    afterPriceLabel.textColor = [UIColor colorWithRed:0.89 green:0.09 blue:0.10 alpha:1.00];
    afterPriceLabel.textAlignment = 2;
    [bottomView addSubview:afterPriceLabel];
    [afterPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bottomView.mas_right).offset(-20 * FONTSIZE);
        make.top.equalTo(lineView.mas_bottom).offset(55 * FONTSIZE);
        make.width.mas_equalTo(200 * FONTSIZE);
        make.height.mas_equalTo(30 * FONTSIZE);
    }];
    
    UIView *priceLineView = [[UIView alloc] init];
    priceLineView.backgroundColor = beforePriceLabel.textColor;
    [beforePriceLabel addSubview:priceLineView];
    CGFloat lineWidth = [self calculateRowWidth:beforePriceLabel.text FontSize:18 Height:20];
    [priceLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(beforePriceLabel.mas_right).offset(0);
        make.top.equalTo(beforePriceLabel.mas_top).offset(9 * FONTSIZE);
        make.width.mas_equalTo(lineWidth * FONTSIZE);
        make.height.mas_equalTo(1);
    }];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 80 * FONTSIZE;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ReceiptTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.lineView.frame = CGRectMake(20 * FONTSIZE, 0, SCREENW - 20 * FONTSIZE, 0.8);
    cell.lineView.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1.0];
    cell.timeImageView.frame = CGRectMake(15 * FONTSIZE, 15 * FONTSIZE, 50 * FONTSIZE, 50 * FONTSIZE);
    cell.timeImageView.image = [UIImage imageNamed:[_imageArr objectAtIndex:indexPath.row]];
    cell.topLabel.font = [UIFont systemFontOfSize:16 * FONTSIZE];
    cell.bottomLabel.font = cell.topLabel.font;
    cell.topLabel.text = [_wordArr objectAtIndex:indexPath.row];
    cell.bottomLabel.text = [_wordArr objectAtIndex:indexPath.row + 3];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
